#!/usr/bin/env python3
# -*- coding:utf-8 -*-

import urllib.request
import urllib.error
import urllib.parse

headers = {'Accept': '*/*',
           'Accept-Language': 'zh-CN,zh;q=0.9',
           'User_Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
                         'Chrome/65.0.3325.181 Safari/537.36'}
value = {'loginPhoneOrEmail': 'qinmu911@163.com', 'loginPassword': ''}
try:
    data = urllib.parse.urlencode(value).encode('utf8')
    response = urllib.request.Request('https://juejin.im/', headers=headers)
    html = urllib.request.urlopen(response)
    result = html.read().decode('utf-8')
    print(result)
except urllib.error.URLError as e:
    if hasattr(e, 'reason'):
        print('错误原因是：%s' % str(e.reason))
except urllib.error.HTTPError as e:
    if hasattr(e, 'code'):
        print('错误状态码是：%s' % str(e.code))
else:
    print('请求成功通过。')
